package com.qf.test.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.test.pojo.DtsUser;
import com.qf.test.service.UserService;
import com.qf.test.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

//http://localhost:8083/admin/user/list?page=1&limit=20&sort=add_time&order=desc
//解决前后端跨域的问题
@CrossOrigin("*")
//把这个类交给spring管理
@RestController
//设置请求的方法
@RequestMapping("/user")
public class UserContller {
    @Autowired
    private UserService userService;
    @GetMapping("/list")
    //admin/user/list?page=1&limit=20&username=1&mobile=1&sort=add_time&order=desc
    public Object list(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "20") Integer limit,

            String username, String mobile,
            @RequestParam(defaultValue = "add_time") String sort,
            @RequestParam(defaultValue = "desc") String order){
        //1.调用service查询数据
        IPage<DtsUser> ipag = userService.findbyid(page, limit, username, mobile, sort, order);
        //2.获取查询到的条数
        long total = ipag.getTotal();
        //获取查到的数据集合
        List<DtsUser> list = ipag.getRecords();

        //3.返回的对象封装成map
        HashMap<String, Object> data = new HashMap<>();
        data.put("total",total);
        data.put("items",list);


        //4.返回给前端

        return ResponseUtil.ok(data);
    }
    /**
     * 会员的审批系统
     */
    @RequestMapping("/approveAgency")
    public Object approveAgency(){
        return ResponseUtil.ok();
    }
    /**
     * 会员推广代理
     * id  是uid
     */
    @RequestMapping("/detailApprove")
    public Object detailApprove(Integer id){
        return ResponseUtil.ok();
    }

}
